<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  这是 A 页面
  <iframe src="http://127.0.0.1:5500/postMessage/b.html" frameborder="0" onload="load()" id="frame"></iframe>

  <script>
    function load() {
      let frame = document.getElementById('frame')
      frame.contentWindow.postMessage('hello B', "http://127.0.0.1:5500")  // 给B页面传数据
      window.onmessage = function(e) {  // 接受B页面返回的数据
        console.log(e.data);
      }
    }
  </script>
</body>
</html>